from abc import ABC, abstractmethod
from .base_card import BasicCard
from typing import Dict, Any, Optional


class Item(BasicCard):
    """Item 基类"""
    
    def __init__(self, card_id: str, name: str, image_path: str, description: str, 
                 cost: int, target_required: bool, effect_type: str):
        super().__init__(card_id, name, image_path, description)
        self.cost = cost
        self.target_required = target_required
        self.effect_type = effect_type
    
    def to_dict(self) -> Dict[str, Any]:
        """将 Item 序列化为字典"""
        data = super().to_dict()
        data.update({
            "type": "Item",  # 强制设置为Item，而不是子类名
            "cost": self.cost,
            "target_required": self.target_required,
            "effect_type": self.effect_type
        })
        return data
    
    @abstractmethod
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用物品，返回效果结果"""
        pass


class HealPotion(Item):
    """治疗药水 - 指定目标 +3 HP"""
    
    def __init__(self, card_id: str, name: str, image_path: str, description: str, cost: int):
        super().__init__(card_id, name, image_path, description, cost, True, "HEAL")
        self.heal_amount = 3
    
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用治疗药水"""
        if not target_id:
            return {"success": False, "error": "Target required"}
        
        # 查找目标
        target = None
        if target_id.endswith("_summoner"):
            # 提取player_id从summoner ID
            summoner_player_id = target_id.split("_summoner")[0]
            target = game_state.get_summoner(summoner_player_id)
        else:
            # 使用instance_id查找
            target = game_state.get_champion_by_instance_id(target_id)
        
        if not target:
            return {"success": False, "error": "Target not found"}
        
        if not target.is_alive():
            return {"success": False, "error": "Target is dead"}
        
        # 执行治疗
        old_hp = target.hp
        target.heal(self.heal_amount)
        
        return {
            "success": True,
            "effect": "heal",
            "target_id": target_id,
            "amount": self.heal_amount,
            "old_hp": old_hp,
            "new_hp": target.hp,
            "message": f"Healed {self.heal_amount} HP"
        }


class LuckyCoin(Item):
    """幸运币 - 本回合 +1 PP"""
    
    def __init__(self, card_id: str, name: str, image_path: str, description: str, cost: int):
        super().__init__(card_id, name, image_path, description, cost, False, "ADD_PP")
        self.pp_bonus = 1
    
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用幸运币"""
        old_pp = game_state.get_current_pp(player_id)
        game_state.add_pp(player_id, self.pp_bonus)
        new_pp = game_state.get_current_pp(player_id)
        
        return {
            "success": True,
            "effect": "add_pp",
            "amount": self.pp_bonus,
            "old_pp": old_pp,
            "new_pp": new_pp,
            "message": f"Gained {self.pp_bonus} PP (now {new_pp} PP)"
        }


class Flag(Item):
    """旗帜 - 二选一效果"""
    
    def __init__(self):
        super().__init__(
            card_id="flag",
            name="Flag",
            image_path="Flag.jpg",
            description="Item: Choose one: 1. All friendly minions get +1/+1; 2. Summon Zhou Yu and Sun Ce",
            cost=3,
            target_required=False,
            effect_type="CHOICE"
        )
    
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用旗帜 - 需要选择效果"""
        return {
            "success": True,
            "effect": "choice_required",
            "choices": [
                {"id": "buff_all", "description": "All friendly minions get +1/+1"},
                {"id": "summon_tokens", "description": "Summon Zhou Yu and Sun Ce"}
            ],
            "message": "Choose an effect"
        }
    
    def use_with_choice(self, game_state, player_id: str, choice_id: str) -> Dict[str, Any]:
        """根据选择执行效果"""
        if choice_id == "buff_all":
            # 效果1: 己方所有随从+1/+1
            battlefield = game_state.battlefields[player_id]
            buffed_count = 0
            for champion in battlefield:
                if champion and champion.is_alive():
                    champion.attack += 1
                    champion.hp += 1
                    buffed_count += 1
            
            return {
                "success": True,
                "effect": "buff_all",
                "buffed_count": buffed_count,
                "message": f"Buffed {buffed_count} minions"
            }
        
        elif choice_id == "summon_tokens":
            # 效果2: 召唤周瑜和孙策
            battlefield = game_state.battlefields[player_id]
            summoned_count = 0
            
            # 召唤周瑜
            for i, slot in enumerate(battlefield):
                if slot is None:
                    from .guard import ZhouYu
                    zhou_yu = ZhouYu()
                    import uuid
                    zhou_yu.instance_id = f"{player_id}_{i}_zhou_yu_{uuid.uuid4().hex[:8]}"
                    zhou_yu.position = i
                    # 设置守护目标为召唤师
                    zhou_yu.guarding_target_id = f"{player_id}_summoner"
                    battlefield[i] = zhou_yu
                    summoned_count += 1
                    break
            
            # 召唤孙策
            for i, slot in enumerate(battlefield):
                if slot is None:
                    from .guard import SunCe
                    sun_ce = SunCe()
                    import uuid
                    sun_ce.instance_id = f"{player_id}_{i}_sun_ce_{uuid.uuid4().hex[:8]}"
                    sun_ce.position = i
                    battlefield[i] = sun_ce
                    summoned_count += 1
                    break
            
            return {
                "success": True,
                "effect": "summon_tokens",
                "summoned_count": summoned_count,
                "message": f"Summoned {summoned_count} tokens"
            }
        
        return {"success": False, "error": "Invalid choice"}


class Fan(Item):
    """扇子 - 选择目标造成5点伤害并恢复己方召唤师5点生命"""
    
    def __init__(self):
        super().__init__(
            card_id="fan",
            name="Fan",
            image_path="Fan.png",
            description="Item: Deal 5 damage to target enemy, restore 5 HP to your summoner",
            cost=7,
            target_required=True,
            effect_type="DAMAGE_HEAL"
        )
    
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用扇子"""
        if not target_id:
            return {"success": False, "error": "Target required"}
        
        # 查找目标
        target = None
        if target_id.endswith("_summoner"):
            # 攻击敌方召唤师
            enemy_id = target_id.split("_summoner")[0]
            target = game_state.get_summoner(enemy_id)
        else:
            # 攻击敌方英雄
            target = game_state.get_champion_by_instance_id(target_id)
        
        if not target:
            return {"success": False, "error": "Target not found"}
        
        if not target.is_alive():
            return {"success": False, "error": "Target is dead"}
        
        # 对目标造成5点伤害
        target_dead = target.take_damage(5)
        
        # 如果目标是Champion且死亡，从战场移除
        if target_dead and not target_id.endswith("_summoner"):
            game_state._remove_dead_champion(target_id)
        
        # 恢复己方召唤师5点生命
        summoner = game_state.get_summoner(player_id)
        old_hp = summoner.hp
        summoner.heal(5)
        
        return {
            "success": True,
            "effect": "damage_heal",
            "target_id": target_id,
            "damage_dealt": 5,
            "target_dead": target_dead,
            "summoner_healed": 5,
            "old_summoner_hp": old_hp,
            "new_summoner_hp": summoner.hp,
            "message": f"Dealt 5 damage to target, healed summoner for 5 HP"
        }


class Tripod(Item):
    """鼎 - 使自己PP上限永久+1，若达到最大值抽2张卡"""
    
    def __init__(self):
        super().__init__(
            card_id="tripod",
            name="Tripod",
            image_path="Tripod.jpg",
            description="Item: Permanently increase your max PP by 1. If max PP reaches 10, draw 2 cards",
            cost=3,
            target_required=False,
            effect_type="INCREASE_MAX_PP"
        )
    
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用鼎"""
        old_max_pp = game_state.max_pp[player_id]
        
        # 增加PP上限
        game_state.max_pp[player_id] = min(10, game_state.max_pp[player_id] + 1)
        new_max_pp = game_state.max_pp[player_id]
        
        result = {
            "success": True,
            "effect": "increase_max_pp",
            "old_max_pp": old_max_pp,
            "new_max_pp": new_max_pp,
            "message": f"Max PP increased to {new_max_pp}"
        }
        
        # 如果达到最大值，抽2张卡
        if new_max_pp == 10:
            drawn_cards = []
            for _ in range(2):
                if game_state.draw_piles[player_id]:
                    card = game_state.draw_piles[player_id].pop(0)
                    game_state.hands[player_id].append(card)
                    drawn_cards.append(card)
            
            result["max_pp_reached"] = True
            result["drawn_cards"] = drawn_cards
            result["message"] += f", drew {len(drawn_cards)} cards"
        
        return result


class Bag(Item):
    """包 - 抽3张卡，若PP上限>=7回复己方召唤师2血"""
    
    def __init__(self):
        super().__init__(
            card_id="bag",
            name="Bag",
            image_path="Bag.jpg",
            description="Item: Draw 3 cards. If max PP >= 7, restore 2 HP to your summoner",
            cost=3,
            target_required=False,
            effect_type="DRAW_CARDS"
        )
    
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用包"""
        # 抽3张卡
        drawn_cards = []
        for _ in range(3):
            if game_state.draw_piles[player_id]:
                card = game_state.draw_piles[player_id].pop(0)
                game_state.hands[player_id].append(card)
                drawn_cards.append(card)
        
        result = {
            "success": True,
            "effect": "draw_cards",
            "drawn_cards": drawn_cards,
            "message": f"Drew {len(drawn_cards)} cards"
        }
        
        # 如果PP上限>=7，回复己方召唤师2血
        if game_state.max_pp[player_id] >= 7:
            summoner = game_state.get_summoner(player_id)
            old_hp = summoner.hp
            summoner.heal(2)
            result["healed"] = True
            result["heal_amount"] = 2
            result["old_hp"] = old_hp
            result["new_hp"] = summoner.hp
            result["message"] += ", healed summoner for 2 HP"
        
        return result


class Sword(Item):
    """剑 - 选择一名敌方单位造成2点伤害，若PP上限>=7额外造成2点伤害"""
    
    def __init__(self):
        super().__init__(
            card_id="sword",
            name="Sword",
            image_path="Sword.jpg",
            description="Item: Deal 2 damage to target enemy champion. If max PP >= 7, deal 2 additional damage",
            cost=1,
            target_required=True,
            effect_type="DAMAGE"
        )
    
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用剑"""
        if not target_id:
            return {"success": False, "error": "Target required"}
        
        # 检查目标是否为敌方单位
        if target_id.endswith("_summoner"):
            # 检查是否为敌方召唤师
            enemy_id = target_id.split("_summoner")[0]
            if enemy_id == player_id:
                return {"success": False, "error": "Cannot target your own summoner"}
        else:
            # 检查是否为敌方champion
            target = game_state.get_champion_by_instance_id(target_id)
            if target:
                # 检查champion是否属于敌方玩家
                target_player = None
                for p_id in game_state.players:
                    if p_id != player_id:
                        battlefield = game_state.battlefields[p_id]
                        for champion in battlefield:
                            if champion and champion.instance_id == target_id:
                                target_player = p_id
                                break
                        if target_player:
                            break
                
                # 如果目标属于当前玩家，则不能攻击
                if target_player == player_id:
                    return {"success": False, "error": "Cannot target your own champion"}
                
                # 如果目标不属于任何玩家，也不能攻击
                if target_player is None:
                    return {"success": False, "error": "Target not found"}
        
        # 查找目标
        target = None
        if target_id.endswith("_summoner"):
            # 攻击敌方召唤师
            enemy_id = target_id.split("_summoner")[0]
            target = game_state.get_summoner(enemy_id)
        else:
            # 攻击敌方champion
            target = game_state.get_champion_by_instance_id(target_id)
        
        if not target:
            return {"success": False, "error": "Target not found"}
        
        if not target.is_alive():
            return {"success": False, "error": "Target is dead"}
        
        # 计算伤害
        damage = 2
        if game_state.max_pp[player_id] >= 7:
            damage += 2
        
        # 造成伤害
        target_dead = target.take_damage(damage)
        
        # 如果目标是Champion且死亡，从战场移除
        if target_dead and not target_id.endswith("_summoner"):
            game_state._remove_dead_champion(target_id)
        
        return {
            "success": True,
            "effect": "damage",
            "target_id": target_id,
            "damage_dealt": damage,
            "target_dead": target_dead,
            "message": f"Dealt {damage} damage to target"
        }


class Shield(Item):
    """盾牌 - 使所有友方Guard hp+3"""
    
    def __init__(self):
        super().__init__(
            card_id="shield",
            name="Shield",
            image_path="Shield.jpg",
            description="Item: All friendly Guards gain +3 HP",
            cost=1,
            target_required=False,
            effect_type="BUFF_GUARDS"
        )
    
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用盾牌"""
        battlefield = game_state.battlefields[player_id]
        guard_cards = ["test_guard", "zhen_ji", "sun_ce", "zhou_yu", "zhang_liang", 
                      "hua_mulan", "liu_bei", "lu_ban", "diao_chan", "li_shuwen", "liu_bang"]
        buffed_count = 0
        
        for champion in battlefield:
            if champion and champion.is_alive() and champion.card_id in guard_cards:
                champion.hp += 3
                buffed_count += 1
        
        return {
            "success": True,
            "effect": "buff_guards",
            "buffed_count": buffed_count,
            "message": f"Buffed {buffed_count} Guards"
        }


class Lance(Item):
    """长矛 - 使一个友方单位的攻击力设定为与hp相等"""
    
    def __init__(self):
        super().__init__(
            card_id="lance",
            name="Lance",
            image_path="Lance.jpg",
            description="Item: Set target friendly unit's attack equal to its HP",
            cost=2,
            target_required=True,
            effect_type="SET_ATTACK"
        )
    
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用长矛"""
        if not target_id:
            return {"success": False, "error": "Target required"}
        
        # 查找目标
        target = game_state.get_champion_by_instance_id(target_id)
        if not target:
            return {"success": False, "error": "Target not found"}
        
        if not target.is_alive():
            return {"success": False, "error": "Target is dead"}
        
        # 验证目标是友方单位
        if target not in game_state.battlefields[player_id]:
            return {"success": False, "error": "Cannot target enemy units"}
        
        # 设置攻击力等于当前HP
        old_attack = target.attack
        target.attack = target.hp
        
        return {
            "success": True,
            "effect": "set_attack",
            "target_id": target_id,
            "old_attack": old_attack,
            "new_attack": target.attack,
            "hp": target.hp,
            "message": f"Set {target.name}'s attack to {target.attack}"
        }


class Bow(Item):
    """弓 - 对所有敌方单位造成2点伤害，若有友方Guard在场改为4点"""
    
    def __init__(self):
        super().__init__(
            card_id="bow",
            name="Bow",
            image_path="Bow.jpg",
            description="Item: Deal 2 damage to all enemy units. If you have friendly Guards, deal 4 damage instead",
            cost=6,
            target_required=False,
            effect_type="AOE_DAMAGE"
        )
    
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用弓"""
        # 检查是否有友方Guard
        battlefield = game_state.battlefields[player_id]
        guard_cards = ["test_guard", "zhen_ji", "sun_ce", "zhou_yu", "zhang_liang", 
                      "hua_mulan", "liu_bei", "lu_ban", "diao_chan", "li_shuwen", "liu_bang"]
        has_guard = any(champion and champion.is_alive() and champion.card_id in guard_cards 
                       for champion in battlefield)
        
        # 确定伤害值
        damage = 4 if has_guard else 2
        
        damaged_count = 0
        killed_count = 0
        
        # 遍历所有敌方玩家
        for enemy_id in game_state.players:
            if enemy_id == player_id:
                continue
            
            # 获取敌方战场
            enemy_battlefield = game_state.battlefields[enemy_id]
            
            # 对每个敌方单位造成伤害
            for champion in enemy_battlefield:
                if champion and champion.is_alive():
                    champion_dead = champion.take_damage(damage)
                    damaged_count += 1
                    
                    if champion_dead:
                        killed_count += 1
                        game_state._remove_dead_champion(champion.instance_id)
        
        return {
            "success": True,
            "effect": "aoe_damage",
            "damage": damage,
            "damaged_count": damaged_count,
            "killed_count": killed_count,
            "message": f"Dealt {damage} damage to {damaged_count} enemy units, killed {killed_count}"
        }


class Helmet(Item):
    """头盔 - 抽2张牌，若有友方Guard在场改为抽3张"""
    
    def __init__(self):
        super().__init__(
            card_id="helmet",
            name="Helmet",
            image_path="Helmet.jpg",
            description="Item: Draw 2 cards. If you have friendly Guards, draw 3 cards instead",
            cost=2,
            target_required=False,
            effect_type="DRAW_CARDS"
        )
    
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用头盔"""
        # 检查是否有友方Guard
        battlefield = game_state.battlefields[player_id]
        guard_cards = ["test_guard", "zhen_ji", "sun_ce", "zhou_yu", "zhang_liang", 
                      "hua_mulan", "liu_bei", "lu_ban", "diao_chan", "li_shuwen", "liu_bang"]
        has_guard = any(champion and champion.is_alive() and champion.card_id in guard_cards 
                       for champion in battlefield)
        
        # 确定抽牌数量
        draw_count = 3 if has_guard else 2
        
        # 抽牌
        drawn_cards = []
        for _ in range(draw_count):
            if game_state.draw_piles[player_id]:
                card = game_state.draw_piles[player_id].pop(0)
                game_state.hands[player_id].append(card)
                drawn_cards.append(card)
        
        return {
            "success": True,
            "effect": "draw_cards",
            "drawn_cards": drawn_cards,
            "count": len(drawn_cards),
            "message": f"Drew {len(drawn_cards)} cards"
        }


class Bandage(Item):
    """绷带 - 抽2张牌并恢复己方召唤师6HP"""
    
    def __init__(self):
        super().__init__(
            card_id="bandage",
            name="Bandage",
            image_path="Bandage.jpg",
            description="Item: Draw 2 cards and restore 6 HP to your summoner",
            cost=4,
            target_required=False,
            effect_type="DRAW_HEAL"
        )
    
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用绷带"""
        # 抽2张牌
        drawn_cards = []
        for _ in range(2):
            if game_state.draw_piles[player_id]:
                card = game_state.draw_piles[player_id].pop(0)
                game_state.hands[player_id].append(card)
                drawn_cards.append(card)
        
        # 恢复召唤师6HP
        summoner = game_state.get_summoner(player_id)
        old_hp = summoner.hp
        summoner.heal(6)
        
        return {
            "success": True,
            "effect": "draw_heal",
            "drawn_cards": drawn_cards,
            "old_hp": old_hp,
            "new_hp": summoner.hp,
            "healed": 6,
            "message": f"Drew {len(drawn_cards)} cards, healed summoner for 6 HP"
        }


class Horse(Item):
    """马 - 若有友方rider在场 抽2张牌"""
    
    def __init__(self):
        super().__init__(
            card_id="horse",
            name="Horse",
            image_path="Horse.jpg",
            description="Item: If you have friendly Riders, draw 2 cards",
            cost=1,
            target_required=False,
            effect_type="DRAW_CARDS"
        )
    
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用马"""
        # 检查是否有友方rider
        battlefield = game_state.battlefields[player_id]
        rider_cards = ["test_rider", "wei_qing", "meng_tian", "qin_liangyu", "ying_zheng", 
                       "sun_quan", "liang_hongyu", "xu_fu", "da_ji"]
        has_rider = any(champion and champion.is_alive() and champion.card_id in rider_cards 
                       for champion in battlefield)
        
        if not has_rider:
            return {
                "success": False,
                "error": "No friendly Riders on battlefield",
                "message": "Need a friendly Rider to use this card"
            }
        
        # 抽2张牌
        drawn_cards = []
        for _ in range(2):
            if game_state.draw_piles[player_id]:
                card = game_state.draw_piles[player_id].pop(0)
                game_state.hands[player_id].append(card)
                drawn_cards.append(card)
        
        return {
            "success": True,
            "effect": "draw_cards",
            "drawn_cards": drawn_cards,
            "count": len(drawn_cards),
            "message": f"Drew {len(drawn_cards)} cards"
        }


class Knife(Item):
    """刀 - 消灭一个敌方单位 友方pp上限减1"""
    
    def __init__(self):
        super().__init__(
            card_id="knife",
            name="Knife",
            image_path="Knife.jpg",
            description="Item: Destroy target enemy unit, friendly PP cap -1",
            cost=2,
            target_required=True,
            effect_type="DESTROY_UNIT"
        )
    
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用刀"""
        if not target_id:
            return {"success": False, "error": "Target required"}
        
        # Knife只能选择敌方champion，不能选择召唤师
        if target_id.endswith("_summoner"):
            return {"success": False, "error": "Knife can only target enemy champions"}
        
        # 查找敌方champion
        target = game_state.get_champion_by_instance_id(target_id)
        if not target:
            return {"success": False, "error": "Target not found"}
        
        # 检查champion是否属于敌方玩家
        target_player = None
        for p_id in game_state.players:
            if p_id != player_id:
                battlefield = game_state.battlefields[p_id]
                for champion in battlefield:
                    if champion and champion.instance_id == target_id:
                        target_player = p_id
                        break
                if target_player:
                    break
        
        if target_player == player_id:
            return {"success": False, "error": "Cannot target your own champion"}
        
        if target_player is None:
            return {"success": False, "error": "Target not found"}
        
        if not target.is_alive():
            return {"success": False, "error": "Target is dead"}
        
        # 消灭目标
        target_dead = target.take_damage(target.hp)  # 造成足够伤害杀死champion
        if target_dead:
            game_state._remove_dead_champion(target_id)
        
        # PP上限减1
        old_max_pp = game_state.max_pp[player_id]
        if game_state.max_pp[player_id] > 0:
            game_state.max_pp[player_id] -= 1
        
        return {
            "success": True,
            "effect": "destroy_unit",
            "target_id": target_id,
            "target_destroyed": True,
            "old_max_pp": old_max_pp,
            "new_max_pp": game_state.max_pp[player_id],
            "message": f"Destroyed target, PP cap reduced to {game_state.max_pp[player_id]}"
        }


class Cannon(Item):
    """炮 - 对所有敌方单位造成2点伤害 友方pp上限减1"""
    
    def __init__(self):
        super().__init__(
            card_id="cannon",
            name="Cannon",
            image_path="Cannon.jpg",
            description="Item: Deal 2 damage to all enemy units, friendly PP cap -1",
            cost=2,
            target_required=False,
            effect_type="AOE_DAMAGE"
        )
    
    def use(self, game_state, player_id: str, target_id: Optional[str] = None) -> Dict[str, Any]:
        """使用炮"""
        damage = 2
        damaged_count = 0
        killed_count = 0
        
        # 遍历所有敌方玩家
        for enemy_id in game_state.players:
            if enemy_id == player_id:
                continue
            
            # 获取敌方战场
            enemy_battlefield = game_state.battlefields[enemy_id]
            
            # 对每个敌方单位造成伤害
            for champion in enemy_battlefield:
                if champion and champion.is_alive():
                    champion_dead = champion.take_damage(damage)
                    damaged_count += 1
                    
                    if champion_dead:
                        killed_count += 1
                        game_state._remove_dead_champion(champion.instance_id)
        
        # PP上限减1
        old_max_pp = game_state.max_pp[player_id]
        if game_state.max_pp[player_id] > 0:
            game_state.max_pp[player_id] -= 1
        
        return {
            "success": True,
            "effect": "aoe_damage",
            "damage": damage,
            "damaged_count": damaged_count,
            "killed_count": killed_count,
            "old_max_pp": old_max_pp,
            "new_max_pp": game_state.max_pp[player_id],
            "message": f"Dealt {damage} damage to {damaged_count} enemy units, killed {killed_count}, PP cap reduced to {game_state.max_pp[player_id]}"
        }
